<?php
include "admin/lib/config.inc.php"; 
	if(isset($_GET['i'])){
		$id = get('i');
		$sql = "SELECT * FROM `noticias`,`categoria_noticia`,`imagem_noticia` WHERE `categoria_noticia_id` LIKE `categoria_noticia`.`id_categoria_noticia` AND `id_noticia` LIKE $id";
		
		//$sql = "SELECT * FROM `noticias` where 1";
		//echo $sql;
		$result = mysql_query($sql);
		

		while($row = mysql_fetch_array($result)){
			$titulo = $row['titulo'];
			$conteudo = $row['conteudo'];
			$created = date('d/m/Y H:i:s', strtotime($row[5]));
			$categoria = ucwords(strtolower($row['descricao_categoria_noticia']));
			
		}
		$sql = "SELECT * FROM `imagem_noticia` WHERE `imagem_noticia`.`noticia_id` LIKE $id";
		
		$result = mysql_query($sql);
		
		//echo $caminho_imagem;
		$n = mysql_num_rows($result);
		
	}
	else{
		header("Location: index.php?pg=pgNotFound");
	}
?>

<div class="container">
		<div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">Not&iacutecias
                    
                </h1>
                <ol class="breadcrumb">
                    <li><a href="index.php">Home</a>
                    </li>
                    <li class="active">noticias</li>
                </ol>
            </div>
        </div>
        <!-- /.row -->

        <!-- Portfolio Item Row -->
        <div class="row">
			<?php 
			
			if($n==1){
			$row = mysql_fetch_array($result);
			$caminho_imagem = $row['caminho_imagem_noticia'];
			$legenda_imagem = $row['legenda_imagem_noticia'];
			?>
			<div class="col-md-12">
                <div class="row">
                	<h3><?php echo $titulo;?></h3><br>
                </div>
                <div class="row">
                	<div class="col-md-4" align="justify">
                		<img width="100%" src="<?php echo "admin/".$caminho_imagem;?>"><br><h6><?php echo $legenda_imagem; ?></h6>
                	</div>
                	<div class="col-md-8">
                		<?php echo "<br>".$conteudo;?>
                	</div>
                </div>
                
                
            </div>
								
			<?php 
			}elseif (n>1){
				
			echo "
			
            <div class='col-md-6'>
                <div id='carousel-example-generic' class='carousel slide' data-ride='carousel'>
                    <!-- Indicators -->
                    <ol class='carousel-indicators'>
	                    <li data-target='#carousel-example-generic' data-slide-to='0' class='active'></li>";
	                    
	                    for($i=1; $i<$n;$i++){
	                    	echo "
					<li data-target='#carousel-example-generic' data-slide-to='$i'></li>
	                    		 ";	
	                    }
	                    echo"
                        
                    </ol>

                    <!-- Wrapper for slides -->
                    <div class='carousel-inner'>";?>
                        
                      <?php   $j=0;
	                        while($row = mysql_fetch_array($result)){
	                        	$caminho_imagem = $row['caminho_imagem_noticia'];
	                        	$legenda_imagem = $row['legenda_imagem_noticia'];
	                        	
	                        	if($j==0){
		                        	echo "
										<div class='item active'>
			                        		<img class='img-responsive' src='admin/$caminho_imagem' alt='$legenda_imagem'>
			                        	</div>
			                        	
		                        	";
	                        	}
	                        	else{
	                        		echo "
										<div class='item'>
										<img class='img-responsive' src='admin/$caminho_imagem' alt='$legenda_imagem'>
										</div>
										
										";
	                        	}
	                        	$j++;
	                        	
	                        }
                        	
                        ?>
                        
                        
                    </div>
                    

                    <!-- Controls -->
                    <a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
                        <span class="glyphicon glyphicon-chevron-left"></span>
                    </a>
                    <a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
                        <span class="glyphicon glyphicon-chevron-right"></span>
                    </a>
                </div>
            </div>
            
            <div class="col-md-6">
                <h3><?php echo $titulo; ?></h3>
                <h6><?php echo $created; ?></h6>
                <div id="corpoNoticia" align="justify"><?php echo $conteudo; ?></div>
                
            </div>
            <?php 
					}//fim do if($n>0)
					
            		else{
							echo "
									<div class='col-md-12'>
					                <h3>$titulo</h3>
					                $conteudo
					                <h3>Project Details</h3>
					                <ul>
					                    <li>Lorem Ipsum</li>
					                    <li>Dolor Sit Amet</li>
					                    <li>Consectetur</li>
					                    <li>Adipiscing Elit</li>
					                </ul>
					            </div>";
            			

            		}
            
            ?>
            

        </div>
 </div>